package wicketcool.converter;

import japa.parser.ast.expr.ClassExpr;
import japa.parser.ast.expr.Expression;
import japa.parser.ast.expr.NameExpr;
import japa.parser.ast.expr.StringLiteralExpr;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import wicketcool.model.types.WCLNormalType;
import wicketcool.model.value.WCLNormalValue;
import wicketcool.model.value.WCLStringValue;
import wicketcool.model.value.WCLValue;

/**
 * User: rabbit
 * Date: Aug 4, 2009
 */
@Component
public class DefaultValueConverter implements ValueConverter {

    @Autowired
    private TypeConverter typeConverter;

    public Expression createExpression(WCLValue value) {
        if (value instanceof WCLStringValue) {
            return new StringLiteralExpr(value.getValue());
        } else if (value instanceof WCLNormalValue) {
            return new NameExpr(value.getValue());
        }
        else {
            return new ClassExpr(typeConverter.createType(new WCLNormalType(value.getValue())));
        }
    }
}
